package org.springblade.tms.module.exceptiontype.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.tms.module.common.dto.DeleteDto;
import org.springblade.tms.module.exceptiontype.base.ExceptionMoldService;
import org.springblade.tms.module.exceptiontype.dto.TMExceptionTypeDTO;
import org.springblade.tms.module.exceptiontype.entity.TMExceptionType;
import org.springblade.tms.module.exceptiontype.vo.TMExceptionTypeVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @projectName: BladeX
 * @package: org.springblade.tms.module.exceptiontype.controller
 * @className: ExceptionMoldController
 * @author: yr
 * @description: 异常类型服务
 * @date: 2022/3/23 10:24
 */
@RestController
@RequestMapping("exceptionType/ExceptionMold")
@Api(value = "异常状态-yr", tags = "异常状态-yr")
public class ExceptionMoldController {
	@Resource
	private ExceptionMoldService exceptionMoldService;

	/**
	 * 分页 异常类型
	 */
	@ApiLog("查询异常类型列表")
	@GetMapping("/list")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "异常类型列表", notes = "传入exceptionType")
	public R<IPage<TMExceptionTypeVO>> list(TMExceptionType exceptionType, Query query) {
		return exceptionMoldService.list(exceptionType, query);
	}

	/**
	 * 新增或修改 异常类型
	 */
	@ApiLog("新增或修改异常类型")
	@PostMapping("/saveOrUpdate")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "新增或修改异常类型", notes = "传入exceptionType")
	public R saveOrUpdate(@Valid @RequestBody TMExceptionTypeDTO exceptionTypeDTO) {
		return exceptionMoldService.saveOrUpdate(exceptionTypeDTO);
	}

	/**
	 * 删除异常类型
	 */
	@ApiLog("删除异常类型")
	@PostMapping("/remove")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "删除异常类型", notes = "传入ids")
	public R remove(@Valid @RequestBody @NotNull DeleteDto deleteDto) {
		return exceptionMoldService.remove(deleteDto.getIds());
	}
}
